//
//  ESTActivityCellHeaderView.m
//  ESTSCRMAPP
//
//  Created by 李贤立 on 2018/9/29.
//  Copyright © 2018年 Capfer. All rights reserved.
//

#import "ESTActivityCellHeaderView.h"
#import "ESTDayWeekMonthView.h"
#import "ESTPickerTipView.h"
#import "ESTActivityModel.h"
@implementation ESTActivityCellHeaderView

- (instancetype)initWithTitle:(NSString *)title {
    if (self = [super init]) {
        TYZLabel *titleLabel = [TYZLabel labelWithText:title labelType:TYZLabelType_MainTitle];
        [self addSubview:titleLabel];
        
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20);
            make.centerY.equalTo(self);
        }];
    }
    return self;
}
- (instancetype)initWithTitle:(NSString *)title more:(NSString *)more {
    if (self = [super init]) {
        TYZLabel *titleLabel = [TYZLabel labelWithText:title labelType:TYZLabelType_MainTitle];
        [self addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20);
            make.centerY.equalTo(self);
        }];
        TYZButton *moreButton = [TYZButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:moreButton];
        [moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(titleLabel);
            make.right.equalTo(self).offset(-20);
        }];
        [moreButton setTitle:more forState:UIControlStateNormal];
        [moreButton setTitleColor:TYZBlueColor forState:UIControlStateNormal];
        moreButton.titleLabel.font = [UIFont systemFontOfSize:CoreInfo.fontSize];
        [moreButton addTarget:self action:@selector(didClickMoreButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}
- (instancetype)initWithActivityData:(NSArray<ESTActivityModel *> *)activityData activityInteger:(NSInteger)activityInteger dateType:(NSInteger)dateType {
    if (self = [super init]) {
        WEAKSELF
        ESTDayWeekMonthView *dateView = [[ESTDayWeekMonthView alloc] initWithDateType:dateType];
        [self addSubview:dateView];
        [dateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-20);
            make.top.equalTo(self).offset(10);
            make.width.mas_equalTo(DateView_ChildViewWidth * 3 + DateView_Padding * 2);
        }];
        [dateView setDidClickDayWeekMonthBlock:^(NSInteger integer) {
            if (weakSelf.didClickDayWeekMonthBlock) {
                weakSelf.didClickDayWeekMonthBlock(integer);
            }
        }];
        NSString *name = activityData[activityInteger].ACTIVITY_NAME;
        if (!name) name = [@"选择活动" S];
        ESTPickerTipView *tipView = [[ESTPickerTipView alloc] init];
        tipView.title = name;
        tipView.textColor = PickerTipViewTextColor_White;
        NSMutableArray *arrM = [NSMutableArray arrayWithCapacity:activityData.count];
        [activityData enumerateObjectsUsingBlock:^(ESTActivityModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [arrM addObject:obj.ACTIVITY_NAME];
        }];
        tipView.dataArray = [arrM mutableCopy];
        tipView.pickerTitle = [@"选择活动" S];
        tipView.selectedValue = @[name];
        [self addSubview:tipView];
        [tipView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(dateView);
            make.left.equalTo(self).offset(20);
        }];
        [tipView setDidChooseNumberBlock:^(NSArray<NSNumber *> *numberArray) {
            if (weakSelf.didClickChooseActivityBlock) {
                weakSelf.didClickChooseActivityBlock(numberArray);
            }
        }];
    }
    return self;
}
- (void)didClickMoreButton {
    if (self.didClickMoreBlock) {
        self.didClickMoreBlock();
    }
}
@end
